##################################################################
# PyngFM is a Python implementation of Ping.fm API.
#
# Version: 1.0
# Author: Andrea Grandi <a _DOT_ grandi _AT_ gmail _DOT_ com>
# License: GPL2
# Website: http://pyngfm.googlecode.com
#
# Note: this code is inspired to PHPingFM project.
##################################################################
from base64 import b64decode


class Message():
    def __init__(self, id=None, method=None, rfc_time=None, unix_time=None,
                 title=None, body=None, services= [], location = None):
        self.__id = id
        self.__method = method
        self.__rfc_time = rfc_time
        self.__unix_time = unix_time
        self.__title = title
        self.__body = body
        self.__services = services
        self.__location = location
        
    @property
    def id(self):
        return self.__id
    
    @property
    def method(self):
        return self.__method
    
    @property
    def rfc_time(self):
        return self.__rfc_time
    
    @property
    def unix_time(self):
        return self.__unix_time
    
    @property
    def title(self):
        if self.__title != None:
            return b64decode(self.__title)
    
    @property
    def body(self):
        if self.__body != None:
            return b64decode(self.__body)
    
    @property
    def services(self):
        return self.__services
    
    @property
    def location(self):
        if self.__location != None:
            return b64decode(self.__location)
    
    def set_id(self, id):
        self.__id = id
        
    def set_method(self, method):
        self.__method = method
        
    def set_rfc_time(self, rfc_time):
        self.__rfc_time = rfc_time
        
    def set_unix_time(self, unix_time):
        self.__unix_time = unix_time
        
    def set_title(self, title):
        self.__title = title
        
    def set_body(self, body):
        self.__body = body
    
    def add_service(self, service_id, service_name):
        service = {'id': service_id, 'name': service_name}
        self.__services.append(service)
    
    def set_location(self, location):
        self.__location = location
